import requests


class TestTHRMLogin:
    # 测试用例1：登录成功
    def test01_login_success(self):
        login_url = "http://ihrm-test.itheima.net/api/sys/login"
        login_header = {"Content-Type": "application/json"}
        login_data = {"mobile": "13800000002", "password": "123456"}
        resp_login = requests.post(url=login_url, headers=login_header, json=login_data)
        assert resp_login.status_code == 200
        assert resp_login.json()["success"] == True
        assert resp_login.json()["code"] == 10000
        assert resp_login.json()["message"] == '操作成功！'

    # 测试用例2：账号错误
    def test02_mobile_error(self):
        login_url = "http://ihrm-test.itheima.net/api/sys/login"
        login_header = {"Content-Type": "application/json"}
        login_data = {"mobile": "", "password": "123456"}
        resp_login = requests.post(url=login_url, headers=login_header, json=login_data)
        assert resp_login.status_code == 200
        assert resp_login.json()["success"] == False
        assert resp_login.json()["code"] == 20001
        assert resp_login.json()["message"] == '用户名或密码错误'

    # 测试用例2：密码错误
    def test03_password_error(self):
        login_url = "http://ihrm-test.itheima.net/api/sys/login"
        login_header = {"Content-Type": "application/json"}
        login_data = {"mobile": "13800000002", "password": "123455"}
        resp_login = requests.post(url=login_url, headers=login_header, json=login_data)
        assert resp_login.status_code == 200
        assert resp_login.json()["success"] == False
        assert resp_login.json()["code"] == 20001
        assert resp_login.json()["message"] == '用户名或密码错误'
